import { Exclude } from 'class-transformer';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  JoinColumn,
  ManyToMany,
  OneToMany,
  JoinTable,
} from 'typeorm';
import { Department } from '../../department/entities/department.entity';
import { Major } from '../../major/entities/major.entity';
import { StudentCourse } from '../../student-course/entities/student-course.entity';
import { ClassInfo } from './../../class-info/entities/class-info.entity';
import { Role } from '../../roles/entities/role.entity';

/**
 * 学生系统表
 */
@Entity()
export class Student {
  @PrimaryGeneratedColumn()
  sid: string;

  @Column({ comment: '学号', unique: true })
  studentNumber: string;

  @Column({ comment: '姓名' })
  s_name: string;

  @Column({ comment: '性别' })
  gender: number;

  @Column({ comment: '密码' })
  @Exclude()
  password: string;

  @Column({ comment: '家庭住址' })
  s_address: string;

  @Column({ comment: '手机号', nullable: true })
  s_tel: number;

  @Column({ comment: '身份证', nullable: true })
  s_id_card: number;

  @Column({ comment: '班级信息表id', nullable: true })
  classInfo_id: number | null;
  @ManyToOne(() => ClassInfo, (classInfo) => classInfo.student, {
    onDelete: 'SET NULL',
    cascade: ['insert', 'update'],
  })
  @JoinColumn({
    name: 'classInfo_id',
  })
  classInfo: ClassInfo;

  @Column({ comment: '学院表id', nullable: true })
  @Exclude()
  department_id: number;
  @ManyToOne(() => Department, (department) => department.student, {
    onDelete: 'SET NULL',
    cascade: ['insert', 'update'],
  })
  @JoinColumn({
    name: 'department_id',
  })
  department: Department;

  @Column({ comment: '专业表id', nullable: true })
  @Exclude()
  major_id: number;
  @ManyToOne(() => Major, (major) => major.student, {
    onDelete: 'SET NULL',
    cascade: ['insert', 'update'],
  })
  @JoinColumn({
    name: 'major_id',
  })
  major: Major;

  @OneToMany(() => StudentCourse, (studentCourse) => studentCourse.student, {
    onDelete: 'SET NULL',
  })
  studentCourse: StudentCourse[];

  @ManyToMany(() => Role, (role) => role.students)
  @JoinTable({
    name: 'student_role',
  })
  roles: Role[];
}
